import random


import requests
# 上传文件
url = "http://192.168.150.84:8088//carRental//file//uploadFile.action"

path = "C:\\Users\\Administrator\\Desktop\\1234.jpg"  # 要上传的文件
# path = r"C:\新建文件夹\1234.jpg"
# mf是uploadFile.aaaction接口定义的参数名
# path 是要上传的文件
# f fileobj 打开文件后，文件对象
s = requests.Session()
with open(path,mode='rb')as f:
    # fs = {"mf":(path,f)} # 二元组 
    fs = {"mf": (path, f,"image/ipeg")}  # 三元组 第三个参数：content_type代表上传文件的类型

    r = s.post(url,files=fs)
    print(r.text) # Content_Type :'multipart/form-data' 请求头中的类型
    print(r.request.headers)
    print(r.json()['data']['src']) # 文件路径



#     添加车辆

url = "http://192.168.150.84:8088/carRental/car/addCar.action"

cs = {"carnumber": "AAAAA%d"%random.randint(11111,99999),
"cartype":'4533',
"color":random.choice(["黑","白"]),
"carimg":r.json()['data']['src'],
"description":'1',
"price": '1',
"rentprice":'1',
"deposit":'1',
"isrenting":'0'
}
r = requests.post(url,params=cs)
print(r.text)



